import { injectable, inject } from 'inversify';
import { ISessionService } from '../interfaces/ISessionService';
import { IRepository } from '../../infrastructure/database/repositories/interfaces/IRepository';
import { Session } from '../../domain/entities/session.entity';
import { TYPES } from '../../infrastructure/ioc/types';

@injectable()
export class SessionService implements ISessionService {
  constructor(@inject(TYPES.SessionRepository) private sessionRepository: IRepository<Session>) {}

  async createSession(participants: string[]): Promise<Session> {
    const session = new Session();
    session.participants = participants;
    session.agentId = 'default-agent';
    session.createdAt = new Date();
    return this.sessionRepository.save(session);
  }

  async getSession(id: string): Promise<Session | null> {
    return this.sessionRepository.findById(id);
  }

  async updateSession(session: Session): Promise<Session> {
    return this.sessionRepository.save(session);
  }

  async getUserSessions(userId: string): Promise<Session[]> {
    return (this.sessionRepository as any).findByParticipant(userId);
  }
}